package com.hancai.config.converter;


import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.hancai.BsServerApplication;
import com.hancai.model.TClient;

import java.math.BigDecimal;
import java.util.List;


/**
 * @author 涵菜
 * @version 1.0
 * 弹幕作者转换器
 * （excel）1--Java（client）
 */
public class BarrageAuthorConverter implements Converter<TClient> {
    @Override
    public TClient convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        //cellData是Excel中读取列表的数据
        BigDecimal numberValue = cellData.getNumberValue();
        // 转换为 Integer
        Integer clientId = numberValue.intValue();
        List<TClient> tClientList = (List<TClient>) BsServerApplication.cacheMap.get("client");
        for (TClient tClient : tClientList) {
            Integer id = tClient.getId();
            if(clientId.equals(id)) {
                return tClient;
            }
        }
        return null;
    }
}
